package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

//添加图书
public class AddOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("新增图书！");

        int currentSize = bookList.getUsedSize();
        if (currentSize < 10) {
            System.out.println("请输入你要添加的图书信息：");
            Scanner scanner = new Scanner(System.in);
            System.out.println("书名：");
            String name = scanner.nextLine();

            System.out.println("作者：");
            String author = scanner.nextLine();

            System.out.println("价格：");
            int price = scanner.nextInt();
            scanner.nextLine();
            System.out.println("类型：");
            String type = scanner.nextLine();

            Book book = new Book(name,author,price,type);

            for (int i = 0; i < currentSize; i++) {
                if (bookList.getBook(i).getName().equals(name)) {
                    System.out.println("书架存在这本书，不能添加！");
                    return;
                }
            }

            bookList.setBook(currentSize,book);
            bookList.setUsedSize(currentSize + 1);
        }else {
            System.out.println("书架存满了！");
        }

    }
}
